Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ParallelToolCalls to ChatCompletionRequest with helper functions #787

Conversation

structwafel
Copy link
Contributor

Describe the change
Openai has by default a parallel_tool_calls set to true, which allows the llm to make multiple tool calls in one response.

This can be opted out of with setting it to false, and ensures the llm only responds with one tool call at a time.

Provide OpenAI documentation link
https://platform.openai.com/docs/guides/function-calling/parallel-function-calling

Describe your solution
We only need to set the field to false, and true for being certain it is true, we can not just use a bool type.
As that would require a custom marshaller for not including it when not set.

I think a *bool works oke here, it is a bit annoying to set a *bool value. Which is why the helper functions have been given: ParallelOptionFalse() and ParallelOptionTrue().

Intended use:

request := openai.ChatCompletionRequest{}
request.Model = completeChatModel
	
request.ParallelToolCalls = openai.ParallelOptionFalse()	

This seemed the best option without resorting to custom types with custom marshallers, or creating a custom marshal for ChatCompletionRequest

Tests
Currently using a version with bool type and no omitempty which has stopped gpt responding with multiple function calls.

Copy link

codecov bot commented Jul 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.88%. Comparing base (774fc9d) to head (c0fbbb6).
Report is 26 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #787      +/-   ##
==========================================
+ Coverage   98.46%   98.88%   +0.42%     
==========================================
  Files          24       26       +2     
  Lines        1364     1343      -21     
==========================================
- Hits         1343     1328      -15     
+ Misses         15        9       -6     
  Partials        6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@structwafel structwafel changed the title added ParallelToolCalls to ChatCompletionRequest with helper functions Feat: ParallelToolCalls to ChatCompletionRequest with helper functions Jul 11, 2024
@structwafel structwafel changed the title Feat: ParallelToolCalls to ChatCompletionRequest with helper functions feat: ParallelToolCalls to ChatCompletionRequest with helper functions Jul 11, 2024
@sashabaranov
Copy link
Owner

Hey @LGXerxes thank you for the PR!

chat.go Outdated Show resolved Hide resolved
@structwafel structwafel requested a review from sashabaranov July 12, 2024 06:56
@sashabaranov sashabaranov merged commit 727944c into sashabaranov:master Jul 12, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants